package com.tmall.testgen.plugin.views.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.tmall.testgen.client.ClientDataCenter;
import com.tmall.testgen.client.socket.SocketClient;
import com.tmall.testgen.plugin.ConsoleFactory;
import com.tmall.testgen.plugin.wizards.GenTestCodeWizad;
import com.tmall.testgen.plugin.wizards.GenTestCodeWizadPage;
import com.tmall.testgen.plugin.wizards.MyMessageDialog;

/**
 * 生成代码action
 * 
 * @author star
 * 
 */
public class GenCodeAction extends Action {
	private Shell shell;
	public GenCodeAction() {
		setText("生成代码");
		setToolTipText("gen code test");
		setImageDescriptor(ImageManeger.getImageDescriptor(ImageManeger.USED_GEN_CODE));
		//this.shell=shell;
	}

	public void run() {
		if(!SocketClient.getInstance().isStart())
			return;
		try {
			//TotalGenHandler.genJavaFile(TargetProjectConfig.getInstance().getTargetProjectPath(), ClientDataCenter.getInstance().getTestName(),  ClientDataCenter.getInstance().getInfoes());
			GenTestCodeWizad wizard = new GenTestCodeWizad();
			
			WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
			
			
			
			
			dialog.setPageSize(600,400 );
			dialog.create();
			
			GenTestCodeWizadPage wp=wizard.getGenTestCodePage();
			if(ClientDataCenter.getInstance().getInfoes()==null||ClientDataCenter.getInstance().getInfoes().size()==0){
				MyMessageDialog.openWarnDialog(null, "干啥玩意啊，测试信息没收集呢就要生成单元测试啊，泡妹子也没有这么着急的！");
				return;
			}
			
			wp.initDataInfoList(ClientDataCenter.getInstance().getDbInfos());
			
			
			dialog.open();
		} catch (Exception e) {
			ConsoleFactory.putError(e);
		}
		
	}
}
